package com.tdk.common.executor

import java.util.concurrent.ScheduledFuture

interface ScheduledExecutor {
    /**
     * post delay task
     *
     * @param r     runnable
     * @param delay delay
     */
    fun postDelay(r: Runnable?, delay: Long)

    /**
     * post interval task
     *
     * @param r        runnable
     * @param delay    delay
     * @param interval interval
     */
    fun postInterval(r: Runnable?, delay: Long, interval: Long)

    /**
     * post interval range task
     *
     * @param r        runnable
     * @param delay    delay
     * @param interval interval
     * @param range    range
     */
    fun postIntervalRange(r: Runnable?, delay: Int, interval: Long, range: Int)

    /**
     * post interval range task
     *
     * @param r         runnable
     * @param onTimeout onTimeout
     * @param delay     delay
     * @param interval  interval
     * @param range     range
     */
    fun postIntervalRange(r: Runnable?, onTimeout: Runnable?, delay: Int, interval: Long, range: Int)

    /**
     * cancel schedule task by future
     *
     * @param future future to cancel
     */
    fun cancel(future: ScheduledFuture<*>?)

    /**
     * cancel schedule task by runnable
     *
     * @param runnable runnable to cancel
     */
    fun cancel(runnable: Runnable?)

    /**
     * cancel all schedule taks
     */
    fun cancelAll()
}